package com.cskaoyan.demo4.processor;

import com.cskaoyan.demo4.anno.WdFlag;
import com.cskaoyan.demo4.service.Animal;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @Description：
 * @Author：BLUEBLANK
 * @Date：2024/4/18 20:01
 */

@Component
public class CustomBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

        // 查看bean是否包含@WdFlag注解
        if(bean.getClass().isAnnotationPresent(WdFlag.class)) {
            // 包含注解，则打印xxx被标记了
            System.out.println(beanName + "被标记了");
        } else if (bean instanceof Animal) {
            // 如果是Animal类型的bean，则打印xxx 正在初始化
            System.out.println(beanName + "正在初始化");
        }


        // } else if ( beanName.equals("InitializationTest") || beanName.equals("applicationConfiguration")) {
        //     // 如果是test和ApplicationConfiguration,则什么都不做
        // }

        return bean;
    }
}
